M291 R"Z-Binding Test" P"Choose an option:" K{"Start","Skip","Cancel"} S4
if input == 1
    M99
elif input == 2
    abort "Error: Z - Binding test cancelled by user."

G91

M564 H0 ; Allow movement without homing
M913 Z60 ; Reduce Z-axis current

M291 R"Position Build Plate" P"Move the build plate all the way down until you hear grinding sound, then raise it up to a safe position for testing." Z1 S3
M913 Z100 ; Reset Z-axis current


; Move Z-axis up and down five times
G91
var iter = 0
while var.iter < 5
    G1 Z-20 F18000
    G1 Z20 F18000
    set var.iter = var.iter + 1
G91
G1 Z-25 F18000

M291 R"Z-Axis Binding Test Result" P"Was the Z-axis motion smooth without any binding, grinding, or unusual sounds?" K{"Motion Was Smooth","Binding Detected"} S4

if input == 0
    M98 P"0:/sys/led/end.g"
    G4 S1
    M98 P"0:/sys/led/resetstatus.g"
    G91
    G1 Z-50 F18000
    M291 R"Success" P"Z - Motor alignment Not Required" S1 T0
elif input == 1
    M98 P"0:/sys/led/fault.g"
    G4 S1
    M98 P"0:/sys/led/resetstatus.g"
    M291 R"Perform Z - Motor alignment Required" P"Perform Z - Motor alignment Required" S1 T0
    abort "Error: Z - Motor binding reported."


M564 H1 ; Restore movement restrictions
G90